﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class CompilationDAO:BaseService
    {
        /// <summary>
        /// 根据发布信息用户和状态查询任务信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="userid"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IList<Compilation> GetListPaging(int page, int pagesize, int userid, int state)
        {
            string hql = "from Compilation where 1=1";
            if (state == -99)
            {
                hql += " and Issuer = " + userid;
            }
            else
            {
                hql += " and Issuer = " + userid+" and State ="+state;
            }
            hql += " order By AddDate Desc";
            return FindList<Compilation>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 根据发布信息用户和状态查询任务信息条目数
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int GetListPaging(int userid, int state)
        {
            string hql = "select count(*) from Compilation where 1=1";
            if (state == -99)
            {
                hql += " and Issuer = " + userid;
            }
            else
            {
                hql += " and Issuer = " + userid + " and State =" + state;
            }
            return Convert.ToInt32(GetValue(hql));
        }
        /// <summary>
        /// 根据领受任务用户和状态查询任务信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="worker"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IList<Compilation> GetListPagingByWorker(int page, int pagesize, string worker, int state)
        {
            string hql = "from Compilation where 1=1";
            if (state == -99)
            {
                hql += " and Worker like '%" + worker+"%'";
            }
            else
            {
                hql += " and Worker like '%" + worker + "%' and State =" + state;
            }
            hql += " order By AddDate Desc";
            return FindList<Compilation>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 根据领受任务用户和状态查询任务信息条目数
        /// </summary>
        /// <param name="worker"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int GetListPagingByWorker(string worker, int state)
        {
            string hql = "select count(*) from Compilation where 1=1";
            if (state == -99)
            {
                hql += " and Worker like '%" + worker+"%'";
            }
            else
            {
                hql += " and Worker like '%" + worker + "%' and State =" + state;
            }
            return Convert.ToInt32(GetValue(hql));
        }
    }
}
